package com.yanqu.road.server.cmd.activity.yingxin;

import com.yanqu.road.pb.activity.YingXinProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.yingxin.YingXinModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ACTIVITY_YINGXIN_DIG_HOT_POT, desc = "迎新夜宴挖火锅")
public class YingXinDigHotPotCmd extends AbstractCommand {

    private int type;
    private int floor;
    private int index;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        YingXinProto.YingXinOpenHotPotReqMsg reqMsg = YingXinProto.YingXinOpenHotPotReqMsg.parseFrom(packet.getBytes());
        type = reqMsg.getType();
        floor = reqMsg.getFloor();
        index = reqMsg.getIndex();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        player.getModule(YingXinModule.class).checkUserData();
        ret = player.getModule(YingXinModule.class).digHotPot(type, floor, index);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            YingXinProto.YingXinOpenHotPotRespMsg.Builder builder = YingXinProto.YingXinOpenHotPotRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_ACTIVITY_YINGXIN_DIG_HOT_POT, builder);
        }
    }
}
